﻿@model IEnumerable<PrjctMngmt.Models.Task>

@{
    ViewBag.Title = "Tasks";
}

<h2>Tasks</h2>

<p>
    @Html.ActionLink("Add new task", "Create")
    <br />
    @Html.ActionLink("Add task assignment", "Create", "TaskAssignment")
</p>

<script type="text/javascript">
    $(function () {
        $("#tabs-tasks").tabs();
    });
</script>

<script type="text/javascript">
    $(document).ready(function () {
        $(".task").click(function () {
            //AJAX call for checkbox item change / task status change
            var id = $(this).closest('td').attr("id")
            $.post("/Task/ToggleTaskStatus?id=" + id, function () { });
        });
    });
</script>

<div id="tabs-tasks">
	<ul>
        @foreach (var proj in (List<PrjctMngmt.Models.Project>)ViewData["Projects"])
        {
            <!-- Project tabs -->
		    <li><a href="#@proj.ProjectID">@proj.Name</a></li>
        }
	</ul>
    @foreach (var proj in (List<PrjctMngmt.Models.Project>)ViewData["Projects"])
    {
	    <div id="@proj.ProjectID">
            <!-- List project's tasks here -->
            <table class="taskTable">
                @foreach (var item in Model)
                {
                    if (item.ProjectID == proj.ProjectID)
                    {
                    <tr>
                        <td id="@item.TaskID" class="taskTd tasks">
                            
                            @if(item.Finished == 1)
                            {
                                @Html.CheckBox("Status", true, new { @class = "task" })
                            }
                            else
                            {
                                @Html.CheckBox("Status", false, new { @class = "task" })
                            }
                            @Html.DisplayFor(modelItem => item.Name)
                        </td>
                        <td class="taskTd">
                            @Html.ActionLink("See assignments", "ShowTaskAssignments", "TaskAssignment", new { id = item.TaskID }, null) |
                            <a href="/Task/Delete?id=@item.TaskID"><img alt="Remove" title="Remove" class="removeTask ButtonLink removeIcon" src="../../Content/themes/base/images/remove-icon.png" /></a>
                            <a href="/Task/Details?id=@item.TaskID"><img alt="Details" title="Details" class="taskDetails ButtonLink detailIcon" src="../../Content/themes/base/images/mag_glass.png" /></a>
                            <a href="/Task/Edit?id=@item.TaskID"><img alt="Edit" title="Edit" class="editTask ButtonLink editIcon" src="../../Content/themes/base/images/edit.png" /></a>
                        </td>
                    </tr>
                    }
                }
            </table>
	    </div>
    }
</div>